Skip to main content

Unit Class

The Unit class is a powerful tool for interacting with and gathering information about units in the game world. It provides a wide range of methods to access various properties and states of a unit, such as health, position, and combat status.

Unit Class Caching System

The Unit class implements a sophisticated caching system to optimize performance. This system is crucial for reducing the number of API calls and improving overall efficiency, especially when dealing with frequently accessed unit data.

Key Features

  1. Tick-based Caching: The cache is cleared and reset each game tick (a very short interval of game time).

  2. Lazy Evaluation: Values are only calculated when they're first requested in a tick.

  3. Method-specific Caching: Each method has its own cache entry, allowing for fine-grained control.

  4. Argument-sensitive: The cache key includes the method's arguments, ensuring different calls with different parameters are cached separately.

Benefits of Caching

  1. Performance Improvement: Repeated calls to the same method within a tick return the cached value, reducing CPU usage and improving addon performance.

  2. Consistency: All calls to a method within the same tick will return the same value, ensuring consistency in your logic.

  3. Reduced API Load: By caching values, we minimize the number of calls to the WoW API, which is especially important for frequently accessed data.